<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: products_media.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright © since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	© 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	© 2002-2003 osCommerce - www.oscommerce.com
* 	© 2003     nextcommerce - www.nextcommerce.org
* 	© 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

function getFileSize($file, $setup = null) {
	if(is_file($file)) {
		$FZ = ($file && is_file($file)) ? filesize($file) : NULL;
		$FS = array("B","kB","MB","GB","TB","PB","EB","ZB","YB");
		
		if(!$setup && $setup !== 0)
		    return number_format($FZ/pow(1024, $I=floor(log($FZ, 1024))), ($i >= 1) ? 2 : 0) . ' ' . $FS[$I];
		elseif ($setup == 'INT') 
			return number_format($FZ);
		else 
			return number_format($FZ/pow(1024, $setup), ($setup >= 1) ? 2 : 0 ). ' ' . $FS[$setup];
	}
}

if(GROUP_CHECK == 'true')
	$group_check = " AND group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";

$content = $db->db_query("SELECT
								content_id,
								content_name,
								content_link,
								content_file,
								content_read,
								file_comment
							FROM
								".TABLE_PRODUCTS_CONTENT."
							WHERE
								products_id = '".$product->data['products_id']."'
							AND
								languages_id = '".(int)$_SESSION['languages_id']."'".$group_check);
						
if($content->_numOfRows) {
	$media_content = array();
	
	while(!$content->EOF) {
		$filename = '';
		$icon = '';
		
		if ($content->fields['content_link'] != '')
			$icon = image(DIR_WS_CATALOG.'admin/images/icons/icon_link.gif');

		elseif($content->fields['content_file'] != '') {
			$sufftm = explode('.', $content->fields['content_file']);
			$suffix = array_reverse($sufftm);
			$icon = image(DIR_WS_CATALOG.'admin/images/icons/icon_'.$suffix[0].'.gif');
		}
		
		if($content->fields['content_link'] != '')
			$filename = '<a title="'.$content->fields['content_name'].'" href="'.$content->fields['content_link'].(SITE_OVERLAYS == 'true'?'&iframe=true&height=600&width=800':'').'" target="_blank"'.(SITE_OVERLAYS == 'true'?' class="shipping"':'').'>';
			
		$filename .= $content->fields['content_name'];
		
		if($content->fields['content_link'] != '')
			$filename .= '</a>';
			
		$button = '';
		if ($content->fields['content_link'] != '') {
			if(preg_match('/.html/i', $content->fields['content_file']) ||
				preg_match('/.htm/i', $content->fields['content_file']) ||
				preg_match('/.txt/i', $content->fields['content_file']) ||
				preg_match('/.bmp/i', $content->fields['content_file']) ||
				preg_match('/.jpg/i', $content->fields['content_file']) ||
				preg_match('/.gif/i', $content->fields['content_file']) ||
				preg_match('/.png/i', $content->fields['content_file']) ||
				preg_match('/.tif/i', $content->fields['content_file'])) {
				
				if(SITE_OVERLAYS == 'true')
					$button = '<a title="" href="'.href_link(FILENAME_MEDIA_CONTENT, 'coID='.$content->fields['content_id'].'&iframe=true').'" class="shipping">'.image_button('button_view.gif', TEXT_VIEW).'</a>';
				else
					$button = '<a onclick="javascript:window.open(\''.href_link(FILENAME_MEDIA_CONTENT, 'coID='.$content->fields['content_id']).'\', \'popup\', \'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no, width=640, height=600\')">'.image_button('button_view.gif', TEXT_VIEW).'</a>';

			} elseif($content->fields['content_file'] != '')
				$button = '<a href="'.href_link('media/products/'.$content->fields['content_file']).'">'.image_button('button_download.gif', TEXT_DOWNLOAD).'</a>';
		}
		$media_content[] = array('icon' => $icon,
								'filename' => $filename,
								'description' => $content->fields['file_comment'],
								'filesize' => getFileSize(DIR_FS_CATALOG.'media/products/'.$content->fields['content_file']),
								'button' => $button,
								'hits' => $content->fields['content_read']);
	
		$content->MoveNext();
	}

	$module_smarty->assign('language', $_SESSION['language']);
	$module_smarty->assign('media_content', $media_content);

	$module_smarty->caching = false;
	$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/products_media.html');

	$info_smarty->assign('MODULE_products_media', $module);
}
?>